import router from '@ohos.router';
import ajax from '../../http/http'
import prompt from '@ohos.prompt';
export default {
    data: {
        img_url:'home1.png',
        picked1:false,
        picked2:false,
        picked3:false,
        boxName:'Name',
        boxTag:'Tag',
        weight:0,
        description:"description"
    },
    onInit() {

    },
    boxNameChange(e){
        this.boxName=e.value;
    },
    boxTagChange(e){
        this.boxTag=e.value;
    },
    boxWeightChange(e){
        this.weight=parseInt(e.value);
    },
    goBack(){
        this.$emit('goBack')
        router.back()
    },
    boxDescriptionChange(e){
      this.description = e.value;
    },
    pick1(){
        if(this.picked1){
            this.picked1=false;
        }else{
            this.picked1=true;
            this.img_url="smart_home/1674055140211949570.png";
            this.picked2=false;
            this.picked3=false;
        }
    },
    pick2(){
        if(this.picked2){
            this.picked2=false;
        }else{
            this.img_url="smart_home/1673998861699383319.png";
            this.picked2=true;
            this.picked1=false;
            this.picked3=false;
        }
    },
    pick3(){
        if(this.picked3){
            this.picked3=false;
        }else{
            this.img_url="smart_home/1674055285888516143.png";
            this.picked3=true;
            this.picked1=false;
            this.picked2=false;
        }
    },

    add_room(){
        let params = {
            "boxName": this.boxName,
            "boxTag": this.boxTag,
            "weight": this.weight,
            "boxGroup": "smart_home",
            "boxImage": this.img_url,
            "description": this.description
        }
        ajax.post('/experiment/box/add',params,(result)=>{
            prompt.showToast({
                message: result.msg
            });
        })
    }
}
